# coding:utf-8
class Watching < ActiveRecord::Base
  attr_accessible :client_id, :account_id, :freq, :sid, :seconds, :sid_name
  belongs_to :client
  belongs_to :account
  scope :by_client, lambda {|client_id| where(["watchings.client_id = ?", client_id])}
  scope :by_account, lambda {|mobile_number| joins(:account).where(["accounts.mobile_number = ?", mobile_number])}
  scope :before_date, lambda {|date| where(["watchings.created_at < ?", 1.days.since(Time.zone.parse(date)).strftime("%Y-%m-%d")])}
  scope :after_date, lambda {|date| where(["watchings.created_at >= ?", date])}

  TVName = {
    '601' => "CCTV-1",
    '602' => "睛彩电影",
    '603' => "CCTV-5",
    '605' => "CCTV-新闻",
    '607' => "本地一套",
    '608' => "本地二套",
    '604' => "睛彩天下"
  }

  def television_name
    TVName[self.sid.to_s]
  end
end
